#include "bullet.h"
#include "resource.h"

void bullet::init(float _x, float _y, float _z, int _timer,float _speed)
{
    x = _x;
    y = _y;
    z = _z;
    
    timer = _timer;
    speed = _speed;
    active = true;
}

int bullet::update()
{
    timer--;
    
    //Wanneer timer niet op 0 staat geef bullet een nieuwe positie anders draw hem niet meer.
    if(timer > 0) 
    {
        y+=speed;
    }
    else
    {
        active = false;
    }
}

void bullet::draw()
{
    if(active)
    {
        //Draw
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        //Go to the position were player is.
        glTranslatef((x-0.1f),(y-2.0f),z);
        glBindTexture(GL_TEXTURE_2D,objBullet.textureid);
        drawobject(&objBullet.model);
        
         //Draw
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        //Go to the position were player is.
        glTranslatef((x+8.0f),(y-2.0f),z);
        glBindTexture(GL_TEXTURE_2D,objBullet.textureid);
        drawobject(&objBullet.model);       
    }
}

float bullet::get_bulletx()
{
    return x;
}

float bullet::get_bullety()
{
    return y;
}

float bullet::get_bulletz()
{
    return z;
}
